<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<%@ taglib prefix="limits" uri="/WEB-INF/tld/limits.tld"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>在线统计</title>
<link rel="stylesheet" type="text/css" href="../../static/js/themes/defalut.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/public.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/ddspstyle.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="../../static/js/themes/icon.css">

<script type="text/javascript" src="../../static/js/jquery.min.js"></script>
<script type="text/javascript" src="../../static/js/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../static/js/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../../static/js/index.js"></script>

<%
	String serverId = request.getParameter("serverId");
%>

<style type="text/css">
	table.tool_bar td {
		padding: 2px;
	}
</style>
</head>
<body>
	<%-- <input type="hidden" id="sessionId" value="${pageContext.session.id}" /> --%>
	<table id="easyui-datagrid" title="账号列表"></table>
	<div id="toolbar" class="easyui_datagrid_toolbar">
		<div class="easyuiSearch">
			<form id="tool_bar_form">
				<table class="tool_bar" cellspacing="0" cellpadding="0" width="90%">
					<tr>
						<td align="left">分组名称：<input type="text" name="groupSchedulesName" style="width: 150px;" onkeydown="onpress();"/></td>
						<td align="left">机顶盒账号：<input type="text" name="f_iocs_serverid" style="width: 150px;" onkeydown="onpress();"/></td>
						<td align="left" colspan="3">
							年份：
							<select name="year" style="width: 100px;">
							</select>
							月份：
							<select name="month" style="width: 100px;">
								<option value="01">01</option>
								<option value="02">02</option>
								<option value="03">03</option>
								<option value="04">04</option>
								<option value="05">05</option>
								<option value="06">06</option>
								<option value="07">07</option>
								<option value="08">08</option>
								<option value="09">09</option>
								<option value="10">10</option>
								<option value="11">11</option>
								<option value="12">12</option>
							</select>
						</td>
					</tr>
					<tr>
						<td align="left" >
							行业客户：<input name="f_cc_companyname" id="f_cc_companyname" readonly="readonly"	style="width: 150px;" value="" class="yl_inp yw_name" /> 
							<input type="hidden" name="f_cc_companyid" id="f_cc_companyid" value=""/>
							<a class="easyui-linkbutton" data-options="iconCls:'icon-ok'" href="javascript:void(0);"
							onclick="orgSelect()">选择</a>
							<limits:uiAuth url="content_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-cancel', plain:true"
									onclick="reSet()">重置</a>
							</limits:uiAuth>
						</td>
						<td align="left">
							<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search', plain:true" onclick="gotoSearch()">查询</a>
							<limits:uiAuth url="online_statistics_excel_list.do">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-save', plain:true"
									onclick="javascript:exportExcel()">导出Excle</a>
							</limits:uiAuth>
						</td>
						<td align="left">
							<limits:uiAuth url="nb_hy_list.jsp">
								<a href="javascript:void(0);" class="easyui-linkbutton"
									data-options="iconCls:'icon-save', plain:true"
									onclick="javascript:openNbPage()">象山组织部用户活跃记录</a>
							</limits:uiAuth>
						</td>
					</tr>
				</table>
			</form>
		</div>
	</div>
	
	<div id="org_list" class="easyui-dialog"
		style="width: 800px; height: 500px; padding-top: 0px;"
		data-options="title:'客户选择', iconCls:'icon-save',modal:true,closed:true,buttons:'#dlg_buttons'">
		<iframe scrolling="auto" frameborder="0"
			style="width: 100%; height: 99%;"></iframe>
	</div>
	
	<script type="text/javascript">
		/* "use strict"; */
		var queryParams;
		var $tool_bar_form = $("#tool_bar_form");
		var $datagrid = $("#easyui-datagrid");
		
		var serverId = '<%=serverId%>';
		if(serverId && serverId != 'null') {
			$tool_bar_form.find("input[name='f_iocs_serverid']").val(serverId);
		}
		
		function EasyuiDatagrid() {
			$datagrid.datagrid({
				url: '../../industry/behavior/online_statistics_list.do',
				nowrap: true,
				striped: true,
				border: false,
				fit: true,
				rownumbers:true,
				queryParams: getGueryParams(),
				columns: [[
					{field:'serverName',title:'客户名称',align:'center',width:280},
					{field:'f_sduas_address',title:'客户地址',align:'center',width:280},
					{field:'f_iocs_serverid',title:'业务账号',align:'center',width:230},
					{field:'orgName',title:'行业客户',align:'center',width:280},
					{field:'groupSchedulesName',title:'分组名称',align:'center',width:180},
					{field:'visitDates',title:'',align:'center',width:850,
						formatter:function(value,row,index){
							var visitDateArr = row.visitDates ? row.visitDates.split(",") : [];
							var amArr = row.amCounts ? row.amCounts.split(",") : [];
							var pmArr = row.pmCounts ? row.pmCounts.split(",") : [];
							var year = $tool_bar_form.find("select[name='year']").val(),
								month = $tool_bar_form.find("select[name='month']").val();
							
							var monthStartDay = 1,
								monthEndDay = new Date(new Date(year, month, 1).getTime() - 1000*60*60*24).getDate();
							
							
							var visitTableStr = "";
							visitTableStr += "<table>";
							visitTableStr += "	<tbody>";
							visitTableStr += "		<tr>";
							
							
							for(var i = monthStartDay; i <= monthEndDay; i ++) {
								var day_str = i < 10 ? ("0" + i) : i;
								var date_str = year + "-" + month + "-" + day_str;
								var isFind = 0;//赋值上下午活跃度
								if(visitDateArr.length > 0) {
									for(var j = 0; j < visitDateArr.length; j ++) {
										if(visitDateArr[j] == date_str) {
											if(amArr[j] == 1&&pmArr[j] == 0){
												isFind =1 ;
											}
											if(amArr[j] == 0&&pmArr[j] == 1){
												isFind =2 ;
											}
											if(amArr[j] == 1&&pmArr[j] == 1||amArr[j] == 0&&pmArr[j] == 0){//以前的统计程序是没有上下午的  默认为上下午都登入
												isFind =3 ;
											}
										}
									}
								}
								if(isFind != 0) {
									var img = '';
									if(isFind == 1){
										img = 'statistics_am.png';
									}else if (isFind == 2) {
										img = 'statistics_pm.png';
									}else {
										img = 'statistics_all.png';
									}
									visitTableStr += "			<td style='padding: 5px 7px; margin: 1px; border: 1px dot #CCC; background-image:url(../../static/images/"+img+")'>" + day_str + "</td>";
								} else {
									visitTableStr += "			<td style='padding: 5px 7px; margin: 1px; border: 1px dot #CCC;'>" + day_str + "</td>";
								}
							}
							
						
							visitTableStr += "		</tr>";
							visitTableStr += "	</tbody>";
							visitTableStr += "</table>";
							
							
							
							return visitTableStr;
						}
					}
				]],
				singleSelect:true,
				pagination:true,
				pageList:[10,20,30,40,50],
				pageSize:10,
				toolbar: '#toolbar'
			});
		}
	
		
		var nowDate = new Date();
		var startYear = nowDate.getFullYear() - 15,
			endYear = nowDate.getFullYear() + 1;
		for(var i = startYear; i <= endYear; i ++) {
			$tool_bar_form.find("select[name='year']").append("<option value='" + i + "'>" + i + "</option>");
		}
		
		$tool_bar_form.find("select[name='year']").val(nowDate.getFullYear());
		$tool_bar_form.find("select[name='month']").val((Array(2).join('0') + (nowDate.getMonth() + 1)).slice(-2));
		
		function getGueryParams(){
			return {
				orgName : $tool_bar_form.find("input[name='f_cc_companyname']").val(),
				f_iocs_orgId : Number($tool_bar_form.find("input[name='f_cc_companyid']").val()),
				groupSchedulesName : $tool_bar_form.find("input[name='groupSchedulesName']").val(),
				f_iocs_serverid : $tool_bar_form.find("input[name='f_iocs_serverid']").val(),
				year : $tool_bar_form.find("select[name='year']").val(),
				month : $tool_bar_form.find("select[name='month']").val()
			};
		}
		var object=null;
		$(function(){
			$.ajax({
				url:"../../pms/industry_orgVo_list.do",
				type:"post",
				data:{"f_po_status":1,
					"f_po_parentId":0,
					"f_po_name":'',page:1,rows:10},
				dataType:"json",
				success:function(data) {
					if(data.total==1){
						console.log(data.rows);
						$("#f_cc_companyid").val(data.rows[0].f_po_id);
						$("#f_cc_company_name").val(data.rows[0].f_po_name);
					}
				}
			});
		});
		var gotoSearch = function(){
			var f_iocs_orgId=0;
			if(Number($tool_bar_form.find("input[name='f_cc_companyid']").val())!=null&&Number($tool_bar_form.find("input[name='f_cc_companyid']").val())!=0){
				f_iocs_orgId=Number($tool_bar_form.find("input[name='f_cc_companyid']").val());
			}
			if(!f_iocs_orgId||f_iocs_orgId==0||f_iocs_orgId==''){
				alert("请选择客户");
				return;
			}
			if(object==null){
				object=new EasyuiDatagrid();
			}
			$datagrid.datagrid('reload',getGueryParams());
		};
		
		function onpress(){
			var event=arguments.callee.caller.arguments[0]||window.event;//消除浏览器差异
				if (event.keyCode == 13){  
				gotoSearch();
			}
		}
		
		function openNbPage(){
			//openDialog($('#org_list'),'../industry/behavior_control/org_update.jsp?idField=f_cc_companyid&nameField=f_cc_companyname');
			window.location.href="../../tmp/nb_hy_list.jsp";
		}
		  
		function orgSelect(){
			openDialog($('#org_list'),'org_update.jsp?idField=f_cc_companyid&nameField=f_cc_companyname');
		}
		function reSet(){
			$("#f_cc_companyname").val("");
			$("#f_cc_companyid").val("");
		}
		
		function exportExcel(){
			var orgName="";
			var f_iocs_orgId=0;
			var groupSchedulesName="";
			var f_iocs_serverid="";
			var year="";
			var month="";
			
			if($tool_bar_form.find("input[name='f_cc_companyname']").val()!=null&&$tool_bar_form.find("input[name='f_cc_companyname']").val()!=""){
				orgName=$tool_bar_form.find("input[name='f_cc_companyname']").val();
			}
			if(Number($tool_bar_form.find("input[name='f_cc_companyid']").val())!=null&&Number($tool_bar_form.find("input[name='f_cc_companyid']").val())!=0){
				f_iocs_orgId=Number($tool_bar_form.find("input[name='f_cc_companyid']").val());
			}
			if($tool_bar_form.find("input[name='groupSchedulesName']").val()!=null&&$tool_bar_form.find("input[name='groupSchedulesName']").val()!=""){
				groupSchedulesName=$tool_bar_form.find("input[name='groupSchedulesName']").val();
			}
			if($tool_bar_form.find("input[name='f_iocs_serverid']").val()!=null&&$tool_bar_form.find("input[name='f_iocs_serverid']").val()!=""){
				f_iocs_serverid=$tool_bar_form.find("input[name='f_iocs_serverid']").val();
			}
			if($tool_bar_form.find("select[name='year']").val()!=null&&$tool_bar_form.find("select[name='year']").val()!=""){
				year=$tool_bar_form.find("select[name='year']").val();
			}
			if($tool_bar_form.find("select[name='month']").val()!=null&&$tool_bar_form.find("select[name='month']").val()!=""){
				month=$tool_bar_form.find("select[name='month']").val();
			}
			
			if(!f_iocs_orgId||f_iocs_orgId==0||f_iocs_orgId==''){
				alert("请选择客户");
				return;
			}
			var object=getGueryParams()
			object.page=1;
			object.rows=1;
			$.ajax({
				url:'../../industry/behavior/online_statistics_list.do',
				dataType : 'json',
				data : object,
				type : 'get',
				success:function(data) {
					if(data.total>5000){
						alert("导出数量大于5000，请修改搜索条件，减少导出数量！目前数量:"+data.total);
					}else{
						var url="../../industry/behavior/online_statistics_excel_list.do?orgName="+orgName+"&f_iocs_orgId="+f_iocs_orgId+"&groupSchedulesName="+groupSchedulesName+"&f_iocs_serverid="+f_iocs_serverid+"&year="+year+"&month="+month;
	        			window.open(url);
					}
				}
			});
		}
	</script>

</body>
</html>